package com.qijian.common.utils.easyexcel.handler;

import com.alibaba.excel.write.style.row.AbstractRowHeightStyleStrategy;
import org.apache.poi.ss.usermodel.Row;

import java.util.Collection;

/**
 * @author gw
 */
public class HideRowHandler extends AbstractRowHeightStyleStrategy {

    private final Collection<Integer> hideRelativeRowIndex;

    private final boolean isNeedHide;

    private final Integer defaultHeadWidth;

    public HideRowHandler(Integer defaultHeadWidth) {
        this.hideRelativeRowIndex = null;
        this.isNeedHide = false;
        this.defaultHeadWidth = defaultHeadWidth;
    }

    public HideRowHandler(Collection<Integer> hideRowIndex, Integer defaultHeadWidth) {
        this.hideRelativeRowIndex = hideRowIndex;
        this.isNeedHide = hideRowIndex != null && hideRowIndex.size() > 0;
        this.defaultHeadWidth = defaultHeadWidth;
    }

    @Override
    protected void setHeadColumnHeight(Row row, int relativeRowIndex) {
        if (isNeedHide) {
            if (hideRelativeRowIndex.contains(row.getRowNum())) {
                row.setHeightInPoints(0);
                return;
            }
        }
        row.setHeightInPoints((float) defaultHeadWidth);
    }

    @Override
    protected void setContentColumnHeight(Row row, int relativeRowIndex) {
        if (isNeedHide) {
            if (hideRelativeRowIndex.contains(relativeRowIndex)) {
                row.setHeightInPoints(0);
            }
        }
    }


}
